package org.vt.scheduleapp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddTodoListActivity extends Activity {
	
	private static final String tag = "AddTodoListActivity";
	
	public void onCreate(Bundle savedInstanceState){
		final Context ctx = this;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_todolist);
		
		final EditText itemName = (EditText) findViewById(R.id.itemName);
		
		Button confirmItem = (Button) findViewById(R.id.confirmItem);
		
		confirmItem.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				String itemTitle = itemName.getText().toString();
				Log.v(tag, "Item Title:= " + itemTitle);
				
				ToDoList todo = new ToDoList(itemTitle);
				ToDoReader reader = new ToDoReader(ctx);
				List<ToDoList> todos = new ArrayList<ToDoList>();
				try{
					todos = reader.getAllTodo();
				}catch (IOException e){
					e.printStackTrace();
				}
				todos.add(todo);
				
				ToDoWriter writer = new ToDoWriter(ctx);
				try{
					writer.writeTodo(todos);
				}catch(IOException e){
					e.printStackTrace();
				}
				AddTodoListActivity.this.finish();
			}
		});
	}

}
